package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.blnoruleklcodevo.BlnoRuleKlcodeCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnoruleklcodevo.BlnoRuleKlcodePageReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnoruleklcodevo.BlnoRuleKlcodeRespVO;
import com.cmc.cloud.cmclink.doc.vo.blnoruleklcodevo.BlnoRuleKlcodeUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.BlnoRuleKlcodeDO;
import com.cmc.cloud.cmclink.doc.service.BlnoRuleKlcodeService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 订舱号提单号规则 三位码")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/Klcode")
@Validated
public class BlnoRuleKlcodeController {

    @Resource
    private BlnoRuleKlcodeService blnoRuleKlcodeService;

    
    @Operation(summary = "创建订舱号提单号规则 三位码")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:bookerThreeCodeMaintain:add')")
    public CommonResult<Void> createBlnoRuleKlcode(@Valid @RequestBody BlnoRuleKlcodeCreateReqVO createReqVO) {
        blnoRuleKlcodeService.createBlnoRuleKlcode(createReqVO);
        return CommonResult.success();
    }

    
    @Operation(summary = "更新订舱号提单号规则 三位码")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:bookerThreeCodeMaintain:edit','doc:bookerThreeCodeMaintain:enable'})")
    public CommonResult<Void> updateBlnoRuleKlcode(@Valid @RequestBody BlnoRuleKlcodeUpdateReqVO updateReqVO) {
        blnoRuleKlcodeService.updateBlnoRuleKlcode(updateReqVO);
        return CommonResult.success();
    }

    
    @Operation(summary = "删除订舱号提单号规则 三位码")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:bookerThreeCodeMaintain:delete')")
    public CommonResult<Void> deleteBlnoRuleKlcode(@PathVariable("id") Long id) {
        blnoRuleKlcodeService.deleteBlnoRuleKlcode(id);
        return CommonResult.success();
    }


    @Operation(summary = "获得订舱号提单号规则 三位码")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<BlnoRuleKlcodeRespVO> getBlnoRuleKlcode(@PathVariable("id") Long id) {
        BlnoRuleKlcodeDO blnoRuleKlcode = blnoRuleKlcodeService.getBlnoRuleKlcode(id);
        return CommonResult.success(BeanUtil.copyProperties(blnoRuleKlcode, BlnoRuleKlcodeRespVO.class));
    }

    
    @Operation(summary = "获得订舱号提单号规则 三位码列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<BlnoRuleKlcodeRespVO>> getBlnoRuleKlcodeList(@RequestParam("ids") Collection<Long> ids) {
        List<BlnoRuleKlcodeDO> list = blnoRuleKlcodeService.getBlnoRuleKlcodeList(ids);
        return CommonResult.success(BeanUtil.copyToList(list,BlnoRuleKlcodeRespVO.class));
    }

    
    @Operation(summary = "获得订舱号提单号规则 三位码分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:bookerThreeCodeMaintain:search')")
    public CommonResult<PageResult<BlnoRuleKlcodeRespVO>> getBlnoRuleKlcodePage(@Valid @RequestBody BlnoRuleKlcodePageReqVO pageVO) {
        PageResult<BlnoRuleKlcodeRespVO> pageResult = blnoRuleKlcodeService.getBlnoRuleKlcodePage(pageVO);
        return CommonResult.success(pageResult);
    }
}
